#ifndef _READ_VIDEO_H_
#define _READ_VIDEO_H_

#include <iostream>
using namespace std;

#include <string.h>

#include <sys/time.h>
#include <unistd.h>
#include <sys/select.h>

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include "frame_header.hh"

#include <queue>


typedef struct {
    IplImage * left;
    frame_header *hleft;
    IplImage * right;
    frame_header *hright;
} stereo_IplImage_t;

enum video_formats {no_format=0, raw_video, ra2_video, avi_video};

typedef struct {
    std::queue<stereo_IplImage_t*> buffer_IplImage_use;
    std::queue<stereo_IplImage_t*> buffer_IplImage_free;
    stereo_IplImage_t * imgs_in_use;

    pthread_mutex_t mutex_use;
    pthread_mutex_t mutex_free;
    
    bool quit;
    enum video_formats video_format;
    int iniframe;
    //CvCapture *videoI;
    //CvCapture *videoD;
    //FILE *rawvideoI;
    //CvSize video_size;
    char *videoI_name;
    char * videoD_name;
    pthread_t pthread;

    int free;
    int use;
    struct timeval oldfilltimeL;
    struct timeval oldfilltimeR;
} video_params_t;



int get_read_images(stereo_IplImage_t **imgs, video_params_t * p, bool free_image=false);
int free_read_images(stereo_IplImage_t **imgs, video_params_t * p);
void * ReadVideo_thread (void * params);
int start_ReadVideo_thread(video_params_t * video_params, bool use_camera, 
			   const char * video_name, const char *format, int ini_frame);



#ifdef _READ_VIDEO_CPP_

pthread_mutex_t mutex_read;


#else

extern pthread_mutex_t mutex_read;

#endif //_READ_VIDEO_CPP_
#endif //_READ_VIDEO_H_


